import 'dart:math';

import 'package:flutter/material.dart';

class LoadingContainer extends StatelessWidget {
  const LoadingContainer(
      {super.key,
      required this.child,
      this.isLoading = false,
      this.cover = false});

  final Widget child;
  final bool isLoading;

  /// 加载动画是否覆盖在原有界面上
  final bool cover;

  @override
  Widget build(BuildContext context) {
    if (cover) {
      return Stack(
        children: [
          child,
          isLoading ? _loadingView() : Container(),
        ],
      );
    } else {
      return isLoading ? _loadingView() : child;
    }
  }

  _loadingView() {
    return const Center(
      child: CircularProgressIndicator.adaptive(),
    );
  }
}
